package com.x.erp.service;

import java.util.List;

import com.x.erp.model.CarLog;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.alibaba.dubbo.config.annotation.Service;
import com.x.erp.dao.DetectionDao;
import com.x.erp.dao.DetectionImageDao;
import com.x.erp.manage.DetectionManage;
import com.x.erp.model.Detection;
import com.x.erp.model.DetectionImage;
import com.x.erp.rpc.DetectionRpcService;
import com.x.framework.exception.BusinessException;
import com.x.framework.exception.ExceptionCode;
import com.x.framework.service.BaseService;

/**
 * 检测单服务
 */
@Component
@Service(interfaceName = "com.x.erp.rpc.DetectionRpcService", timeout = 60000)
public class DetectionService extends BaseService implements DetectionRpcService {

	@Autowired
	private DetectionImageDao detectionImageDao;// 检测单图片DAO

	@Autowired
	private DetectionDao detectionDao;// 检测单信息Dao

	@Autowired
	private DetectionManage detectionManage;// 检测单信息Manage

	/**
	 * 查询检测单信息列表
	 * 
	 * @param detection
	 * @return
	 */
	@Override
	public List<Detection> selectDetectionList(Detection detection) {
		try {
			return detectionDao.selectDetectionList(detection);
		} catch (Exception e) {
			throw new BusinessException(ExceptionCode.EXCEPTION_CODE0000, e);
		}
	}

	/**
	 * 查询检测单信息数量
	 * 
	 * @param detection
	 * @return
	 */
	@Override
	public int selectDetectionNum(Detection detection) {
		try {
			return detectionDao.selectDetectionNum(detection);
		} catch (Exception e) {
			throw new BusinessException(ExceptionCode.EXCEPTION_CODE0000, e);
		}
	}

	/**
	 * 新增检测单信息
	 * 
	 * @param detection
	 * @return
	 */
	@Override
	public Detection insertDetection(Detection detection) {
		try {
			return detectionManage.insertDetection(detection);
		} catch (Exception e) {
			throw new BusinessException(ExceptionCode.EXCEPTION_CODE0000, e);
		}
	}

	/**
	 * 修改检测单信息
	 * 
	 * @param detection
	 * @return
	 */
	@Override
	public int updateDetection(Detection detection) {
		try {
			return detectionManage.updateDetection(detection);
		} catch (Exception e) {
			throw new BusinessException(ExceptionCode.EXCEPTION_CODE0000, e);
		}
	}
	/**
	 * 修改检测单信息（包括图片、车辆状态）
	 * 
	 * @param detection
	 * @return
	 */
	@Override
	public int updateDetectionInfo(Detection detection, CarLog carLog) {
		try {
			return detectionManage.updateDetectionInfo(detection, carLog);
		} catch (Exception e) {
			throw new BusinessException(ExceptionCode.EXCEPTION_CODE0000, e);
		}
	}

	/**
	 * 查询检测单信息
	 * 
	 * @param detection
	 * @return
	 */
	@Override
	public Detection selectDetection(Detection detection) {
		try {
			return detectionDao.selectDetection(detection);
		} catch (Exception e) {
			throw new BusinessException(ExceptionCode.EXCEPTION_CODE0000, e);
		}
	}

	/**
	 * 新增检测单图片信息
	 * 
	 * @param detectionImage
	 * @return
	 */
	@Override
	public DetectionImage insertDetectionImage(DetectionImage detectionImage) {
		try {
			return this.insert(detectionImage);
		} catch (Exception e) {
			throw new BusinessException(ExceptionCode.EXCEPTION_CODE0000, e);
		}
	}

	/**
	 * 修改检测单图片信息
	 * 
	 * @param detectionImage
	 * @return
	 */
	@Override
	public int updateDetectionImage(DetectionImage detectionImage) {
		return this.update(detectionImage);
	}

	/**
	 * 查询检测单图片信息
	 * 
	 * @param detectionImage
	 * @return
	 */
	@Override
	public List<DetectionImage> selectDetectionImageList(DetectionImage detectionImage) {
		try {
			return detectionImageDao.selectDetectionImageList(detectionImage);
		} catch (Exception e) {
			throw new BusinessException(ExceptionCode.EXCEPTION_CODE0000, e);
		}
	}

}
